<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('schedule_tasks', function (Blueprint $table) {
            $table->id()->comment('任务ID');  // 主键ID
            $table->string('user_id')->nullable(false)->comment('用户ID');  // 关联用户ID，唯一
            $table->string('name')->nullable(false)->comment('任务名称');  // 任务名称，唯一
            $table->string('time_type')->nullable(false)->comment('延迟类型');
            $table->string('delay_time')->nullable()->comment('任务延迟时间');
            $table->string('jitter_time')->nullable()->comment('抖动时间');
            $table->string('cron_expression')->comment('Cron表达式');  // 定时任务表达式，默认每分钟执行
            $table->boolean('is_active')->default(false)->comment('是否启用');  // 任务是否启用，默认不启动
            $table->timestamps();  // 创建和更新时间

            $table->index('user_id')->comment('用户ID索引');
            $table->index('is_active')->comment('启用状态索引');
            $table->index('created_at')->comment('创建时间索引');
        });
          
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('schedule_tasks');
    }
};
